//
//  ComputerRoomExamDetailController.m
//  Learn
//
//  Created by 迟建国 on 2024/4/4.
//  Copyright © 2024 迟建国. All rights reserved.
//

#import "ComputerRoomExamDetailController.h"
#import "ScoreAnalysisCollectionViewCell.h"
#import "QuestionContentCollectionViewCell.h"

@interface ComputerRoomExamDetailController ()<UICollectionViewDelegate, UICollectionViewDataSource>
@property (nonatomic, strong) UICollectionView *collectionView;
@end

@implementation ComputerRoomExamDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = rgbHex(0xF5F5F5, 1);
    [self setUI];
    [self setNavUI];
    // Do any additional setup after loading the view.
}

- (void)setUI {
    
    UIImageView *topBgView = [[UIImageView alloc] init];
    topBgView.image = [UIImage imageNamed:@"icon_result_bg"];
    topBgView.backgroundColor = UIColor.grayColor;
    [self.view addSubview:topBgView];
    [topBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.equalTo(self.view);
        make.height.offset(287 + NavigationBarHeight);
    }];
    
    UILabel *scoreL = [[UILabel alloc] init];
    scoreL.text = @"0";
    scoreL.textColor = UIColor.whiteColor;
    scoreL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:66];
    [self.view addSubview:scoreL];
    [scoreL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).offset(NavigationBarHeight + 20);
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    UILabel *desL = [[UILabel alloc] init];
    desL.text = @"得分率45%";
    desL.textColor = UIColor.whiteColor;
    desL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:18];
    [self.view addSubview:desL];
    [desL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(scoreL.mas_bottom).offset(10);
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(10, 183 + NavigationBarHeight, SCREEN_W - 20, 104)];
    bgView.backgroundColor = [UIColor whiteColor];
    [bgView setCornerOnTop:15];
    [self.view addSubview:bgView];
    
    UILabel *maxL = [[UILabel alloc] init];
    maxL.text = @"班级最高分";
    maxL.textColor = rgba(142, 142, 142, 1);
    maxL.textAlignment = NSTextAlignmentCenter;
    maxL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    [bgView addSubview:maxL];
    [maxL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(bgView.mas_left).offset(28);
        make.bottom.equalTo(bgView.mas_bottom).offset(-20);
    }];
    UILabel *gradeMaxL = [[UILabel alloc] init];
    gradeMaxL.text = @"29.1/30";
    gradeMaxL.textColor = rgba(142, 142, 142, 1);
    gradeMaxL.textAlignment = NSTextAlignmentCenter;
    gradeMaxL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:24];
    [bgView addSubview:gradeMaxL];
    [gradeMaxL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_top).offset(20);
        make.left.equalTo(bgView.mas_left).offset(13);
    }];
    
    UILabel *gradeAvageL = [[UILabel alloc] init];
    gradeAvageL.text = @"29.1/30";
    gradeAvageL.textColor = rgba(142, 142, 142, 1);
    gradeAvageL.textAlignment = NSTextAlignmentCenter;
    gradeAvageL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:24];
    [bgView addSubview:gradeAvageL];
    [gradeAvageL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_top).offset(20);
        make.centerX.equalTo(bgView.mas_centerX);
    }];
    UILabel *avageL = [[UILabel alloc] init];
    avageL.text = @"班级平均分";
    avageL.textColor = rgba(142, 142, 142, 1);
    avageL.textAlignment = NSTextAlignmentCenter;
    avageL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    [bgView addSubview:avageL];
    [avageL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgView.mas_bottom).offset(-20);
        make.centerX.equalTo(gradeAvageL.mas_centerX);
    }];
    
    UILabel *numL = [[UILabel alloc] init];
    numL.text = @"完成人数";
    numL.textColor = rgba(142, 142, 142, 1);
    numL.textAlignment = NSTextAlignmentCenter;
    numL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:12];
    [bgView addSubview:numL];
    [numL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(bgView.mas_bottom).offset(-20);
        make.right.equalTo(bgView.mas_right).offset(-31);
    }];
    UILabel *finishNumL = [[UILabel alloc] init];
    finishNumL.text = @"40";
    finishNumL.textColor = rgba(142, 142, 142, 1);
    finishNumL.textAlignment = NSTextAlignmentCenter;
    finishNumL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:24];
    [bgView addSubview:finishNumL];
    [finishNumL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(bgView.mas_top).offset(20);
        make.centerX.equalTo(numL.mas_centerX);
    }];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.sectionInset = UIEdgeInsetsMake(10, 0, 10, 0);
    layout.minimumLineSpacing = 10;
    UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 287 + NavigationBarHeight, SCREEN_W, SCREEN_H - NavigationBarHeight - SafeAreaBottomHeight - 287) collectionViewLayout:layout];
    collectionView.backgroundColor = UIColor.clearColor;
    collectionView.delegate = self;
    collectionView.dataSource = self;
    collectionView.showsVerticalScrollIndicator = NO;
    collectionView.showsHorizontalScrollIndicator = NO;
//    collectionView.alwaysBounceVertical = NO;
//    self.extendedLayoutIncludesOpaqueBars = YES;
    if (@available(iOS 11.0, *)) {
        collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }
    [collectionView registerNib:[UINib nibWithNibName:@"ScoreAnalysisCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"ScoreAnalysisCollectionViewCell"];
    [collectionView registerNib:[UINib nibWithNibName:@"QuestionContentCollectionViewCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"QuestionContentCollectionViewCell"];
    
    [self.view addSubview:collectionView];
    self.collectionView = collectionView;
}

- (void)setNavUI {
    UIView *nav = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, NavigationBarHeight)];
    nav.backgroundColor = UIColor.clearColor;
    [self.view addSubview:nav];
//    self.nav = nav;
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"icon_back_white"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [nav addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(nav.mas_left).offset(5);
        make.bottom.equalTo(nav.mas_bottom);
        make.width.offset(50);
        make.height.offset(44);
    }];
    
    UILabel *titleL = [[UILabel alloc] init];
    titleL.text = @"期末考考前练1";
    titleL.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];
    titleL.textColor = UIColor.whiteColor;
    titleL.textAlignment = NSTextAlignmentCenter;
    [nav addSubview:titleL];
    [titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(nav.mas_bottom);
        make.centerX.equalTo(nav.mas_centerX);
        make.height.offset(44);
    }];

}
#pragma collectionView

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return 2;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) {
        ScoreAnalysisCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"ScoreAnalysisCollectionViewCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"ScoreAnalysisCollectionViewCell" owner:self options:nil] lastObject];
        }
    //    cell.model = self.model;
        return cell;
    } else {
        QuestionContentCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"QuestionContentCollectionViewCell" forIndexPath:indexPath];
        if (!cell) {
            cell = [[[NSBundle mainBundle]loadNibNamed:@"QuestionContentCollectionViewCell" owner:self options:nil] lastObject];
        }
    //    cell.model = self.model;
        return cell;
    }
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        return CGSizeMake(SCREEN_W - 20, 425);
    } else {
        return CGSizeMake(SCREEN_W - 20, 186);
    }
}
- (void)back {
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
}
@end
